//
//  DCPersonMsgViewController.m
//  JiuyaoMotorcade
//
//  Created by 大橙子 on 2018/11/29.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCPersonMsgViewController.h"
#import "DCPersonMsgTableViewCell.h"
#import "DCChangePhoneNumVC.h"
@interface DCPersonMsgViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSArray *titleArray;
@property (nonatomic,strong) NSArray *textArray;

@end

@implementation DCPersonMsgViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"基本资料";
    self.view.backgroundColor = [UIColor whiteColor];
    self.titleArray = @[@"公司名称",@"公司所在地",@"联系人",@"联系电话",@"资料认证"];
    self.textArray = @[Str_IsEmpty([UserInfo shareInstance].record.name)?@"xx运输公司":[UserInfo shareInstance].record.name,@"北京市顺义区",@"老张",Str_IsEmpty([UserInfo shareInstance].record.tel)?@"15012345678":[UserInfo shareInstance].record.tel,@"已认证"];
    [self setUpMainView];
}

-(void)setUpMainView {
    
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(10, 20, ScreenWidth-20, self.titleArray.count *50) style:UITableViewStylePlain];
    //    tableView.backgroundColor = [UIColor redColor];
    tableView.scrollEnabled = NO;
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];
    
    UIButton *loginOutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    loginOutBtn.frame = CGRectMake(40, tableView.bottom+50, ScreenWidth - 40*2, 40);
    [loginOutBtn setTitle:@"退出登录" forState:UIControlStateNormal];
    loginOutBtn.backgroundColor = BlueColor;
    loginOutBtn.layer.cornerRadius = 18;
    loginOutBtn.clipsToBounds = YES;
    [loginOutBtn addTarget:self action:@selector(loginBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:loginOutBtn];
}
-(void)loginBtnDidClick {
    DCLogFunc;
    [SVProgressHUD showWithStatus:nil];
    NSDictionary *info = [NSDictionary dictionary];
    [DCServiceTool postWithUrl:Logout_URL params:info success:^(id responseObject) {
        if ([responseObject[@"code"] integerValue] == 0) {
            [DCTool loginOut];
        }else{
            [self showMessage:responseObject[@"msg"] afterDelay:1.0];
        }
        [SVProgressHUD dismiss];
    } failure:^(NSError *error) {
        [SVProgressHUD dismiss];
        [self showMessage:error.localizedDescription afterDelay:1.0];
    }];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.titleArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    DCPersonMsgTableViewCell *cell = [DCPersonMsgTableViewCell cellWithTableView:tableView];
    cell.titleLabel.text = self.titleArray[indexPath.row];
    cell.subTextLabel.text = self.textArray[indexPath.row];
    
    __weak typeof(self) weakself = self;
    if (indexPath.row == 3) {
        cell.isShowBtn = YES;
        [cell.selectedBtn setTitle:@"更换" forState:UIControlStateNormal];
        cell.block = ^{
            DCChangePhoneNumVC *changePhone = [[DCChangePhoneNumVC alloc]init];
            [weakself.navigationController pushViewController:changePhone animated:YES];
        };
    }
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}
-(void)dimission {//离职
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否离职" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        DCLog(@"离职");
    }];
    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alertVC addAction:sureAction];
    [alertVC addAction:cancleAction];
    [self presentViewController:alertVC animated:YES completion:nil];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
